//
//  BlueSkyfundTableViewController.m
//  GoodWayClient
//
//  Created by newhuidong on 16/1/4.
//  Copyright © 2016年 HuiDong. All rights reserved.
//

#import "BlueSkyfundTableViewController.h"
#import "AFNetworking.h"
#import "Constant.h"
#import "AppDelegate.h"
#import "MJRefresh.h"
#import "MJRefreshAutoFooter.h"
#import "BlueskyFundTableViewCell.h"
@interface BlueSkyfundTableViewController (){
    NSString * _string;
}

@property(nonatomic,assign)int pageSize;

@property(nonatomic,strong)NSArray * array;

@property(nonatomic,strong)NSMutableArray * mutableArray;


@end

@implementation BlueSkyfundTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=@"蓝天基金";
    [self  setupRefresh];
    
    [self reachability];

}
-(void)viewWillAppear:(BOOL)animated{
    
    self.navigationController.navigationBar.tintColor=[UIColor whiteColor];
    
}
-(void)reachability{
    
    [[AFNetworkReachabilityManager sharedManager]startMonitoring];
    //__weak typeof (self) weakSelf =self;
    
    [[AFNetworkReachabilityManager sharedManager]setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        switch (status) {
            case AFNetworkReachabilityStatusUnknown:
                //
                NSLog(@"无网络");
                break;
            case AFNetworkReachabilityStatusNotReachable:
                //
                break;
            case AFNetworkReachabilityStatusReachableViaWWAN:
                //
                break;
            case AFNetworkReachabilityStatusReachableViaWiFi:
                //
                NSLog(@"无线网络");
                break;
            default:
                break;
        }
        
    }];
    
    
    
    
    
}
-(void)viewDidAppear:(BOOL)animated{
    
    
    AFHTTPRequestOperationManager * manager=[AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    NSDictionary * dic=[NSDictionary dictionary];
    AppDelegate * tempAppDelegate = (AppDelegate*)[[UIApplication sharedApplication]delegate];
    
    dic=@{@"token":tempAppDelegate.token,@"pageSize":@6,@"pageIndex":@1};
    NSString * url =[NSString stringWithFormat:@"%@%@",url2,@"GetBlueSkeyMoney"];
    NSLog(@"URL:%@",url);
    NSLog(@"token:%@",tempAppDelegate.token);
    [manager POST:url parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        NSDictionary *dic1 = (NSDictionary *)responseObject;
        
        
        self.mutableArray =[[dic1 valueForKey:@"Data"]valueForKey:@"list"];
        
        NSLog(@"Money:%@",[self.mutableArray valueForKey:@"Money"]);
        
        
        // _string =[NSString stringWithString:[self.mutableArray valueForKey:@"CreateTime"]];
        
        NSLog(@"CreateTime:%@",[self.mutableArray valueForKey:@"CreateTime"]);
        
        
        //self.moneyLabel.text= [self.mutableArray valueForKey:@"Money"];
        
        [self.tableView reloadData] ;
        
        NSLog(@"list:%@",self.mutableArray);
        
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"%@",error);
        
    }];
}

-(void)setupRefresh{
    
    self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
    
}
-(void)loadMoreData{
    
    
    
    
}
-(NSMutableArray*)mutableArray{
    
    if (!_mutableArray) {
        
        _mutableArray=[NSMutableArray array];
        
    }
    return _mutableArray;
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.mutableArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    BlueskyFundTableViewCell*cell=[BlueskyFundTableViewCell blueskuFundWithTableView:tableView];
    
    cell.dic=self.mutableArray[indexPath.row];
    
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 65;
    
}
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
    
//    OrderdetailsViewController*orderVC=[[OrderdetailsViewController alloc]init];
//    [self.navigationController pushViewController:orderVC animated:YES];
    
}


-(void)loadNewData{
    
    NSLog(@"加载数据");
    
}

@end
